<template>
	<view>
		<!-- 导航栏 -->
		<u-navbar v-if="finalNavbarObject.show" :title="finalNavbarObject.title"
			:title-size="finalNavbarObject.titleSize" :is-back="finalNavbarObject.isBack"
			:back-icon-name="finalNavbarObject.backIconName" :back-text="finalNavbarObject.backText">
		</u-navbar>

		<!-- 轮播区域 -->
		<view v-if="finalSwiperObject.list.length > 0">
			<u-swiper :list="finalSwiperObject.list" :name='finalSwiperObject.name' :height="finalSwiperObject.height"
				:indicator-pos="finalSwiperObject.indicatorPos" :effect3d="finalSwiperObject.effect3d"
				:autoplay="finalSwiperObject.autoplay" :interval="finalSwiperObject.interval"
				:circular="finalSwiperObject.circular" :duration="finalSwiperObject.duration"
				:border-radius="finalSwiperObject.borderRadius" @click="handleSwiper()">
			</u-swiper>
		</view>

		<!-- 四宫格区域 -->
		<view class="navBox" :class="finalSwiperObject.list.length>0?'swiper':''"
			v-if="fourboxGridList.list.length > 0">
			<view class="navItems" v-for="(item,index) in fourboxGridList.list" :key="index"
				@click="handlefourboxGrid(item)">
				<view class="items">
					<text class="navName">{{item.title}}</text>
					<view class="tag">GO TO CONTROLS <u-icon name="arrow-right"></u-icon></view>
				</view>
				<u-icon :name="getImgUrl(item.thumb)" :size="120"></u-icon>
			</view>
		</view>

		<!-- 用户信息区域 -->
		<view>
			<!-- 登录 -->
			<view class="my-info"
				:class="{'info': finalSwiperObject.list.length > 0,'two': finalSwiperObject.list.length === 0 && finalSwiperObject.list.length > 0}">
				<view class="headImg">
					<image :src="userinfo.headImg"></image>
				</view>
				<view class="userinfo" @click="toUrl()">
					<view style="font-weight: bold;font-size: 35upx;">{{shortenText(userinfo.list.member_name)}}</view>
					<view>{{userinfo.list.level_name}}</view>
				</view>
				<view class="storeinfo">
					<view class="storeItem" @click="toUrl()">
						<view class="itemnum">{{shortenText(userinfo.list.credit)}}</view>
						<view>积分</view>
					</view>
					<view class="storeItem" @click="toUrl()">
						<view class="itemnum">{{shortenText(0)}}</view>
						<view>优惠券</view>
					</view>
					<view class="storeItem" @click="toUrl()">
						<view class="itemnum">{{shortenText(0)}}</view>
						<view>购物卡</view>
					</view>
				</view>
				<view class="memberinfo" @click="$u.route()">
					<view style="line-height: 47upx;">
						<u-icon name="grid" :size="45"></u-icon>
						<view>会员码</view>
					</view>
				</view>
			</view>

			<!-- 未登录 -->
			<!-- <view class="my-info" :class="{
						'isLogin': vuex_isLogin,
					    'info': finalSwiperObject.list.length > 0,
					    'two': finalSwiperObject.list.length === 0 && finalSwiperObject.list.length > 0
					  }">
				<view class="headImg">
					<image :src="headImg"></image>
				</view>

				<view class="headName">
					<view class="headLogn" @click="toLogo">注册/登录</view>
					<view style="text-align: left;">登录后查看更多精彩</view>
				</view>
			</view> -->
		</view>

		<!-- 多个功能选项区域 -->
		<view class="funBox" v-if="multifunction.length > 0">
			<view class="funTitle">更多服务</view>
			<u-grid :col="3" :border="true" class="custom-grid">
				<u-grid-item v-for="(item, index)  in multifunction" :key="index" @click="handleFun(item)">
					<u-icon :name="getImgUrl(item.thumb)" :size="90"></u-icon>
					<view class="grid-text">{{ item.title }}</view>
				</u-grid-item>
			</u-grid>
		</view>

		<!-- 魔方区域 -->
		<view class="mineBox" v-if="rcList.length > 0">
			<view class="leftBox">
				<view class="upperLeft">
					<image :src="rcList[0].thumb"></image>
				</view>
				<view class="leftLower">
					<image :src="rcList[1].thumb"></image>
				</view>
			</view>
			<view class="rightBox">
				<swiper class="imgSwiper" :autoplay="true" :interval="3000" :circular="true" :indicator-dots="true"
					:touchable="false">
					<swiper-item class="imgSwiperItem" v-for="(item,index) in rcList.slice(2)"
						@click="onlineEvents(item)" :key="index">
						<view class="imgs" v-if="item.thumb"
							:style="{ backgroundImage: 'url(' + getImgUrl(item.thumb) + ')'}"></view>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>

</template>
<script>
	/**
	 * ---------------导航栏区域参数---------------
	 * @property {Object} navbarObject 导航栏参数
	 * show {Boolean} 导航栏是否显示
	 * isBack {Boolean} 是否显示导航栏左边返回图标和辅助文字
	 * titleSize {Number} 导航栏标题字体大小，单位rpx
	 * backIconName {String} 左边返回图标的名称，只能为uView自带的图标
	 * backText {String} 返回图标右边的辅助提示文字
	 * -------------------------------------------
	 * 
	 * ---------------轮播区域参数---------------
	 * @property {Object} swiperObject 轮播参数
	 * list {Array} 轮播数据
	 * name {String} list参数中的属性名
	 * indicatorPos {String} 指示器的位置 topLeft / topCenter / topRight / bottomLeft / bottomRight 默认topRight
	 * height {String | Number} 轮播图组件高度，单位rpx 默认400
	 * effect3d {Boolean} 是否开启3D效果 默认 false
	 * autoplay {Boolean} 是否自动播放 默认 true
	 * interval {String | Number} 自动轮播时间间隔，单位ms 默认2500
	 * circular {Boolean} 是否衔接播放 默认 true
	 * duration {String | Number} 切换一张轮播图所需的时间，单位ms 默认500
	 * borderRadius {String | Number} 轮播图圆角值，单位rpx 默认 8
	 * -----------------------------------------
	 * 
	 * ---------------四宫格区域参数---------------
	 * @property {Object} fourboxGridList 轮播参数
	 * list {Array} 数据
	 * -----------------------------------------
	 * 
	 * ---------------用户信息区域参数---------------
	 * @property {Object} userinfo 用户信息参数
	 * list {Array} 用户数据
	 * -----------------------------------------
	 * 
	 * ---------------多功能区域数据---------------
	 * @property {Array} multifunction 多功能参数
	 * -----------------------------------------
	 */

	export default {
		props: {
			// 魔方数据
			rcList: {
				type: Array,
				require: false
			},
			// 多功能
			multifunction: {
				type: Array,
				require: false
			},
			// 用户信息
			userinfo: {
				type: Object,
				require: false
			},
			// 四宫格
			fourboxGridList: {
				type: Object,
				require: false
			},
			// 轮播
			swiperObject: {
				type: Object,
				require: false,
			},
			// 导航栏
			navbarObject: {
				type: Object,
				required: false, // 改为非必填
			}
		},
		data() {
			return {

			}
		},
		computed: {

			shortenText() {
				return text => {
					if (typeof text === 'number') {
						const numString = text.toString(); // 将数字转换为字符串
						if (numString.length > 3) {
							return numString.slice(0, 3) + '...';
						} else {
							return numString;
						}
					} else if (typeof text === 'string') {
						if (text.length > 2) {
							return text.slice(0, 2) + '...';
						} else {
							return text;
						}
					} else {
						return text;
					}
				};
			},
			// 最终轮播参数配置
			finalSwiperObject() {
				return {
					list: [], //
					name: '', //list参数中的属性名
					indicatorPos: 'topRight', //指示器的位置 topLeft / topCenter / topRight / bottomLeft / bottomRight 默认bottomCenter
					height: '400', //轮播图组件高度，单位rpx 默认250
					effect3d: false, //	是否开启3D效果 默认 false
					autoplay: true, //是否自动播放 默认 true
					interval: 2500, //自动轮播时间间隔，单位ms 默认2500
					circular: true, //是否衔接播放 默认 true
					duration: 500, //切换一张轮播图所需的时间，单位ms 默认500
					borderRadius: 8, //	轮播图圆角值，单位rpx 默认 8
					...this.swiperObject
				}
			},
			// 最终导航栏参数配置
			finalNavbarObject() {
				return {
					show: true, //是否显示导航栏
					isBack: true, //是否显示导航栏左边返回图标和辅助文字 默认 true
					titleSize: 30, //导航栏标题字体大小，单位rpx 默认44
					backIconName: '', //左边返回图标的名称，只能为uView自带的图标 默认	nav-back
					backText: '', //返回图标右边的辅助提示文字
					...this.navbarObject
				}
			}
		},
		methods: {
			// 多功能事件
			handleFun(item) {
				this.$emit('handleFun', item)
			},
			// 轮播事件
			handleSwiper(index) {
				this.$emit('handleSwiper', this.finalSwiperObject.list[index])
			},
			// 四宫格事件
			handlefourboxGrid(item) {
				this.$emit('handlefourboxGrid', item)
			}
		}
	}
</script>
<style lang="scss">
	// 轮播区域
	.swiper {
		position: relative;
		top: -70upx;
	}

	// 四宫格区域

	.navBox {
		background: #fff;
		padding: 20upx;
		margin: 0 30upx;
		margin-top: 20upx;
		margin-bottom: 20upx;
		border-radius: 20upx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.navItems {
			width: 50%;
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;
			padding: 20upx 0;

			.items {
				padding: 20upx 0;
				display: flex;
				flex-direction: column;
				justify-content: center;
				text-align: center;

				.navName {
					color: #fff;
					font-size: 34upx;
					font-weight: bold;
					letter-spacing: 5upx;
					margin-left: 5upx;
					color: black;
				}

				.tag {
					font-size: 20upx;
					margin: 5upx 0;
				}
			}


		}

		.navItems:not(:nth-child(2n)) {
			border-right: 1px dashed rgba(0, 0, 0, 0.2);
		}

		.navItems:nth-child(n+3) {
			border-top: 1px dashed rgba(0, 0, 0, 0.2);
		}
	}

	// 用户区域

	.isLogin {
		margin-top: 20upx !important;
	}

	.info {
		margin: 20upx 30upx !important;
		margin-top: -70upx !important;
	}

	.two {
		margin: 20upx 30upx !important;
	}


	.my-info {
		display: flex;
		margin: 20upx 30upx;

		border-radius: 20upx;
		background-color: #fff;
		padding: 40upx 10upx;
		text-align: center;
		justify-content: space-between;

		.headImg {
			width: 15%;
			height: 100upx;
			border-radius: 50%;
			border: 1px solid #ebebeb;
			padding: 20upx;
			background-color: #ebebeb;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.userinfo {
			text-align: center;
			line-height: 47upx;
		}

		.storeinfo {
			text-align: center;
			display: flex;
			justify-content: space-between;

			.storeItem {
				margin: 0 15upx;
				line-height: 47upx;

				.itemnum {
					font-size: 35upx;
					font-weight: bold;
				}
			}
		}

		.memberinfo {}

		.headName {
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			margin-left: 20upx;
			width: 80%;

			.headLogn {
				text-align: left;
				font-size: 40upx;
				font-weight: bold;
			}

			.headSign-in {
				display: flex;
				justify-content: space-between;
			}
		}
	}

	// 多功能区域
	.funBox {
		margin: 0 30upx;
		margin-bottom: 20upx;
		border-radius: 20upx;
		background-color: #fff;

		.funTitle {
			padding: 20upx;
			margin: 0 10upx;
			font-size: 28upx;
		}

		.custom-grid {
			border-radius: 20upx !important;
		}

		.grid-text {
			margin-top: 10upx;
			font-size: 28upx;
		}
	}

	// 魔方区域
	.mineBox {
		margin: 0 30upx;
		background-color: #fff;
		border-radius: 10upx;
		display: flex;
		justify-content: space-around;

		.leftBox {
			width: 50%;
			margin: 5upx;

			.upperLeft {
				display: flex;
				height: 155upx;
				margin-bottom: 5upx;

				image {
					border: 1px solid red;
					width: 100%;
					height: 100%;
					border-radius: 8upx;
				}
			}

			.leftLower {
				height: 155upx;
				margin-top: 5upx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 8upx;
				}
			}
		}

		.rightBox {
			margin: 5upx;
			width: 50%;

			.imgSwiper {
				height: 100%;

				.imgSwiperItem {
					.imgs {
						background-size: 100% 100%;
						height: 100%;
						border-radius: 8upx;
					}
				}
			}
		}
	}
</style>